package fr.nts.framework.database.jpa.model;

import java.io.Serializable;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.slf4j.Logger;

/**
 * Représente un objet modèle de base pour l'API JPA
 * 
 * @author sco
 * @version 1.0.0
 */
public abstract class AJPAModel<T extends Object> implements Serializable{
    
    private static final long serialVersionUID = 1L;

    /*
     * (non-Javadoc)
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals(Object object){
        if(this == object){
            return true;
        }
        if(!(object instanceof AJPAModel<?>)){
            return false;
        }

        return new EqualsBuilder().appendSuper(super.equals(this))
                                  .append(getId(),
                                		  this.getId())
                                  .isEquals();
    }
    

    /*
     * (non-Javadoc)
     * @see java.lang.Object#hashCode()
     */
    @Override
    public int hashCode(){
        int hashCode = 0;
        hashCode = 29 * hashCode + (getId() == null ? 0 : getId().hashCode());
        
        return hashCode;
    }
    
    
    // GETTER / SETTER
    abstract public T getId();

    abstract public void setId(final T id);

    abstract protected Logger getLog();
}